Skip to content

router: match longest entrypoint path prefix#389

Open
avinxshKD wants to merge 1 commit into
volcano-sh:mainfrom
avinxshKD:fix/router-longest-path-prefix
Open

router: match longest entrypoint path prefix#389
avinxshKD wants to merge 1 commit into
volcano-sh:mainfrom
avinxshKD:fix/router-longest-path-prefix

Conversation

@avinxshKD

Copy link
Copy Markdown

/kind bug

What this PR does / why we need it:

Fixes router entrypoint selection when multiple pathPrefix values overlap.

The router was picking the first prefix match, so a runtime with / before /api could route /api/foo to the / entrypoint. It also treated /api2 as matching /api.

This changes the selection to use the longest valid prefix match and keeps path boundaries sane.

Which issue(s) this PR fixes:
Fixes #388

Special notes for your reviewer:

Added focused tests for overlapping prefixes and /api2 boundary behavior.

Does this PR introduce a user-facing change?:

Router now selects the longest valid sandbox entrypoint path prefix when routing invocation requests.

@volcano-sh-bot volcano-sh-bot added the kind/bug Something isn't working label Jun 17, 2026
@volcano-sh-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign yaozengzeng for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@volcano-sh-bot

Copy link
Copy Markdown
Contributor

Welcome @avinxshKD! It looks like this is your first PR to volcano-sh/agentcube 🎉

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the upstream URL determination logic to match the longest path prefix among sandbox entrypoints and introduces a helper function for path boundary matching, along with unit tests. The review feedback suggests improving the robustness of the path matching logic by normalizing leading and trailing slashes, and adding a defensive nil check for the sandbox parameter to prevent potential nil pointer dereferences.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread pkg/router/handlers.go
Comment thread pkg/router/handlers.go
@avinxshKD

Copy link
Copy Markdown
Author

Hey @LiZhenCheng9527 @hzxuzhonghu checked this while looking at the router path selection logic.

Current code picks the first HasPrefix match, so /can steal /api/foo depending on spec order. Also /api2 matches /api.
Longest valid prefix match should fix this cleanly.

Pls take a look when free.

@codecov-commenter

codecov-commenter commented Jun 17, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 58.76%. Comparing base (524e55e) to head (0e84798).
⚠️ Report is 179 commits behind head on main.

Files with missing lines Patch % Lines
pkg/router/handlers.go 93.33% 0 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #389       +/-   ##
===========================================
+ Coverage   47.57%   58.76%   +11.19%     
===========================================
  Files          30       36        +6     
  Lines        2819     3475      +656     
===========================================
+ Hits         1341     2042      +701     
+ Misses       1338     1225      -113     
- Partials      140      208       +68     
Flag Coverage Δ
unittests 58.76% <93.33%> (+11.19%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

},
wantHost: "10.0.0.2:8080",
},
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test only covers the boundary case when a / entrypoint exists. With only /api configured, /api2/run still falls through to the first entrypoint, so it can still route to /api; is that fallback behavior intended?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree, added a case for that.

With only /api configured, /api2/run does not match /api, it falls back to the first entrypoint, same as the existing router behavior. This change only affects which matched prefix wins. PTAL

Signed-off-by: Avinash Kumar Deepak <avinash8655279@gmail.com>
Copilot AI review requested due to automatic review settings July 16, 2026 07:47
@avinxshKD
avinxshKD force-pushed the fix/router-longest-path-prefix branch from 9b99ab4 to 0e84798 Compare July 16, 2026 07:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@acsoto

acsoto commented Jul 16, 2026

Copy link
Copy Markdown
Member

/lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working lgtm size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Router should use longest valid pathPrefix match for sandbox entrypoints

5 participants